<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('表格传值给父页面')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
<div class="container-div">

    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>学生姓名：</label>
                            <input type="text" name="studentName"/>
                        </li>
                        <li>
                            <label>学号：</label>
                            <input type="text" name="studentNo"/>
                        </li>
                        <li>
                            <label>年级：</label>
                            <select   id='gradeId' name='gradeId' class="selectpicker">
                            </select>
                        </li>
                        <li>
                            <label>班级名称：</label>
                            <select   id='classId' name='classId' class="selectpicker">
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>


<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<script th:src="@{/js/common/add_grade.js}"></script>
<script th:inline="javascript">
    $(document).ready(function(){

        $.ajax({
            type: "post",
            url:ctx + "school/grade/getGradeList",
            async:false,
            dataType: "json",
            success: function(res){
                if (null != res) {
                    var html = '<option value="">所有</option>';
                    Object.keys(res).forEach(function(key){
                        html += '<option value="' + res[key].id + '" data-tokens="'+ res[key].gradeName+'">' + res[key].gradeName+ '</option>';
                    });
                    $("#gradeId").html(html);
                    //必须加，刷新select
                    $("#gradeId").selectpicker('refresh');
                }
            }
        });


        //绑定bootstrap-select事件
        $.ajax({
            type: "post",
            url:ctx + "school/classInfo/getClassList",
            async:false,
            dataType: "json",
            success: function(res){
                if (null != res) {
                    var html = '<option value="">所有</option>';
                    Object.keys(res).forEach(function(key){
                        html += '<option value="' + res[key].id + '" data-tokens="'+ res[key].className+'">' + res[key].className+ '</option>';
                    });
                    $("#classId").html(html);
                    //必须加，刷新select
                    $("#classId").selectpicker('refresh');
                }
            }
        });
    });

    var editFlag = [[${@permission.hasPermi('school:student:edit')}]];
    var removeFlag = [[${@permission.hasPermi('school:student:remove')}]];
    var statusDatas = [[${@dict.getType('sys_data_status')}]];
    var prefix = ctx + "school/student";

    $(function() {
        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "学生信息",
            columns: [{
                checkbox: true
            },
            {
                field: 'id',
                title: 'id',
                visible: false
            },
            {
                field: 'studentNo',
                title: '学号'
            },
            {
                field: 'studentName',
                title: '学生姓名'
            },
            {
                field: 'gradeName',
                title: '年级'
            },
            {
                field: 'className',
                title: '班级名称'
            },
            {
                field: 'status',
                title: '状态',
                formatter: function(value, row, index) {
                   return $.table.selectDictLabel(statusDatas, value);
                }
            }]
        };
        $.table.init(options);
    });

    function submitHandler(index, layero) {
        var rows = $.table.selectFirstColumns();
        var studentName = $.table.selectColumns("studentName");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.close();
        // 父页面的方法
        // parent.selectUsers();
        // 父页面的变量
        parent.$('#studentId').val(rows.join());
        parent.$('#studentName').val(studentName.join());
    }
</script>
</body>
</html>